# 2010-08-08, Matthew C. Cluver, matthew.cluver@gmail.com
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted.
#  
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

define openvz::vzctl::create (
		$os_tmpl='',
		$origin_smpl='',
		$ct_ip_address='',
		$ct_nameserver='',
		$ct_hostname='',
		$ct_name=''
) {

 		file{"/etc/vz/conf/${name}.conf":
 					owner  => root,
					group  => root,
    				mode   => 640,
 					ensure => present,		
 		}

    	exec { "create container $name":
      				command		=> "vzctl --verbose create ${name} --ostemplate ${os_tmpl} --config ${origin_smpl}",
      				creates		=> "/etc/vz/conf/${name}.conf",
      				timeout 	=> 7200,
      	}
     
	    if $ct_ip_address != "" { openvz::conf { "${name}_${ct_ip_address}": param => "IP_ADDRESS", value => "${ct_ip_address}", id => "${name}", } }
	    if $ct_hostname != "" { openvz::conf { "${name}_${ct_hostname}": param => "HOSTNAME", value => "${ct_hostname}", id => "${name}", } }
	    if $ct_name != "" { openvz::conf { "${name}_${ct_name}": param => "NAME", value => "${ct_name}", id => "${name}", } }
	    if $ct_nameserver != "" { openvz::conf { "${name}_${ct_nameserver}": param => "NAMESERVER", value => "${ct_nameserver}", id => "${name}", } }
	    
}